package com.cold.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cold.common.domain.Host;
import com.cold.manage.service.IHostService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cold.common.annotation.Log;
import com.cold.common.core.controller.BaseController;
import com.cold.common.core.domain.AjaxResult;
import com.cold.common.enums.BusinessType;
import com.cold.common.utils.poi.ExcelUtil;
import com.cold.common.core.page.TableDataInfo;

/**
 * 主机Controller
 * 
 * @author cold
 * @date 2024-02-29
 */
@RestController
@RequestMapping("/manage/host")
public class HostController extends BaseController
{
    @Autowired
    private IHostService hostService;

    /**
     * 查询主机列表
     */
    @PreAuthorize("@ss.hasPermi('system:host:list')")
    @GetMapping("/list")
    public TableDataInfo list(Host host)
    {
        startPage();
        List<Host> list = hostService.selectHostList(host);
        return getDataTable(list);
    }

    /**
     * 导出主机列表
     */
    @PreAuthorize("@ss.hasPermi('system:host:export')")
    @Log(title = "主机", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Host host)
    {
        List<Host> list = hostService.selectHostList(host);
        ExcelUtil<Host> util = new ExcelUtil<Host>(Host.class);
        util.exportExcel(response, list, "主机数据");
    }

    /**
     * 获取主机详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:host:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hostService.selectHostById(id));
    }

    /**
     * 新增主机
     */
    @PreAuthorize("@ss.hasPermi('system:host:add')")
    @Log(title = "主机", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Host host)
    {
        return toAjax(hostService.insertHost(host));
    }

    /**
     * 修改主机
     */
    @PreAuthorize("@ss.hasPermi('system:host:edit')")
    @Log(title = "主机", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Host host)
    {
        return toAjax(hostService.updateHost(host));
    }

    /**
     * 删除主机
     */
    @PreAuthorize("@ss.hasPermi('system:host:remove')")
    @Log(title = "主机", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hostService.deleteHostByIds(ids));
    }
}
